package com.mrd.base.page;

import java.io.Serializable;

/**
 * <p> application name: sample <p> copyright: Copyright@2012 明睿达科技有限公司
 */

/**
 * 分页对象，如果不设置分页大小则默认为15，如果不设置当前页码则默认为1
 *
 * @author qiul
 */
public class Page implements Serializable {

    private static final long serialVersionUID = 5246003672063853875L;
    /**
     * 当前页码，默认为第一页
     */
    private Integer currentPage = 1;
    /**
     * 总记录数
     */
    private Integer totle;
    /**
     * 分页大小，默认为15
     */
    private Integer pageSize = 15;
    /**
     * 当前页码开始编号(相对总数)
     */
    private Integer currentPageStartNo;
    /**
     * 当前页码结束编号(相对总数)
     */
    private Integer currentPageLastNo;
    /**
     * 总页数
     */
    private Integer totlePage;
    /**
     * 当前页是否是最后一页
     */
    private boolean hasNextPage = true;
    /**
     * 当前页是否是首页
     */
    private boolean hasPrePage = true;

    /**
     * 根据当前页码，总记录数，分页大小初始化分页参数
     */
    public Page(Integer currentPage, Integer totle, Integer pageSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totle = totle;
        resetPage();
    }

    /**
     * 总记录数分页参数,默认当前页码为1，当前分页带下为15
     */
    public Page(Integer totle) {
        this.totle = totle;
        resetPage();
    }

    /**
     * 更新分页相关参数，总页数，当前起始页，当前结束页
     */
    private void resetPage() {
        totlePage = (totle - 1) / pageSize + 1;
        if (currentPage == 1) {
            hasPrePage = false;
        }
        if (currentPage == totlePage) {
            hasNextPage = false;
        }
        if (currentPage > 0 && currentPage <= totlePage) {
            currentPageStartNo = (currentPage - 1) * pageSize + 1;
            currentPageLastNo = currentPage * pageSize;
        }
    }

    public Page() {
        super();
    }

    /**
     * 设置当前页码
     */
    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
        resetPage();
    }

    /**
     * 重设分页大小
     */
    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
        resetPage();
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public Integer getTotle() {
        return totle;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public Integer getCurrentPageStartNo() {
        return currentPageStartNo;
    }

    public Integer getCurrentPageLastNo() {
        return currentPageLastNo;
    }

    public Integer getTotlePage() {
        return totlePage;
    }

    public boolean isHasNextPage() {
        return hasNextPage;
    }

    public boolean isHasPrePage() {
        return hasPrePage;
    }

    public void setTotle(Integer totle) {
        this.totle = totle;
    }

    public void setCurrentPageStartNo(Integer currentPageStartNo) {
        this.currentPageStartNo = currentPageStartNo;
    }

    public void setCurrentPageLastNo(Integer currentPageLastNo) {
        this.currentPageLastNo = currentPageLastNo;
    }

    public void setTotlePage(Integer totlePage) {
        this.totlePage = totlePage;
    }

    public void setHasNextPage(boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }

    public void setHasPrePage(boolean hasPrePage) {
        this.hasPrePage = hasPrePage;
    }

}
